package zhongbo.java.air.dictionary.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhongbo.java.air.dictionary.exception.BusinessException;
import zhongbo.java.air.dictionary.exception.ExceptionCode;
import zhongbo.java.air.dictionary.mapper.AirCraftMapper;
import zhongbo.java.air.dictionary.model.AirCraft;
import zhongbo.java.air.dictionary.service.IAirCraftService;
import zhongbo.java.air.dictionary.vo.PageVo;
import zhongbo.java.air.dictionary.vo.RestResultVo;

/**
 * 服务业
 */
@Service
public class AirCraftServiceImpl implements IAirCraftService {
   @Autowired
    AirCraftMapper airCraftMapper;
    @Override
    public int addAir(AirCraft airCraft) {
        airCraft.setId(null);
        if (airCraft == null && airCraft.equals("")){
            throw new BusinessException(ExceptionCode.AIR_CRAFT_NULL);
        }
        int add = airCraftMapper.insert(airCraft);
        return add;
    }

    @Override
    public void delete(String id) {
        if (id ==null && id.equals("")){
            throw new BusinessException(ExceptionCode.ID_NULL);
        }
        airCraftMapper.deleteById(id);
    }

    @Override
    public int update(AirCraft airCraft) {
        if (airCraft == null && airCraft.equals("")){
            throw new BusinessException(ExceptionCode.AIR_CRAFT_NULL);
        }
        int update = airCraftMapper.updateById(airCraft);

        return update;
    }


    @Override
    public AirCraft selectById(String id) {
        if (id == null && id.equals("")){
            throw new BusinessException(ExceptionCode.ID_NULL);
        }
        AirCraft airCraft = airCraftMapper.selectById(id);
        return airCraft;
    }


    @Override
    public PageVo page(String airline, Integer pageNumber, Integer pageSize) {
        QueryWrapper<AirCraft> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(airline)){
            queryWrapper.like("airline",airline);
        }
        IPage<AirCraft> pageParam = new Page<>(pageNumber,pageSize);
        IPage<AirCraft> AirIPage = airCraftMapper.selectPage(pageParam,queryWrapper);
        return new PageVo<>(AirIPage);
    }

}
